!pip install plotly
Requirement already satisfied: plotly in c:\programdata\anaconda3\lib\site-packages (4.14.3) Requirement already satisfied: retrying>=1.3.3 in c:\programdata\anaconda3\lib\site-packages (from plotly) (1.3.3) Requirement already satisfied: six in c:\programdata\anaconda3\lib\site-packages (from plotly) (1.16.0)
#%%
import scipy.integrate as spi
import numpy as np
import pylab as pl
beta = 0.1934 # S ->I 감염율 = beta 를 구하지 못해서 논문에 나온 beta 값 참조 ( 2020.02.10 중국논문발표)
# R0*gamma/S0 = beta
#우리나라도 중국과 마찬가지로 2차 지역감염이 시작되고 전염력이 2/18 당시 매우 높았던것으로 보여 논문의 beta 도입.
gamma = 1/14 # I ->R 회복율 = 평균 회복기간의 역수
t_inc = 1.0
t_end = 150.0
# 2/18 31번확진자 나온날 기준으로 초기 SIR 모델 만듦.
S0 = int(input('Input the accumulated number of tests: '))
I0 = int(input('Input the accumulated number of positive results: '))
R0 = int(input('Input the accumulated number of releases: '))
# S0 = 9772 ; I0 = 31; R0 = 12
N = S0 + I0 + R0
S0 = S0 /N # susceptible hosts
I0 = I0 /N # infectious hosts
R0 = R0 /N # recovered hosts
Input = (S0, I0, 0.0)
Input
def simple_SIR(INT, t):
'''The main set of equation'''
Y=np.zeros((3))
X = INT # S0, I0
Y[0] = -beta * X[0] * X[1]
Y[1] = beta*X[0]*X[1] - gamma * X[1]
Y[2] = gamma * X[1]
return Y # for spicy.odeint
t_start =0.0 ;
t_range = np.arange(t_start, t_end + t_inc, t_inc)
SIR= spi.odeint(simple_SIR, Input, t_range)
12
pl.figure(figsize=(15,8))
pl.plot(SIR[:, 0], '-g', label='Susceptibles')
pl.plot(SIR[:, 2], '-k', label='Recovereds')
pl.plot(SIR[:, 1], '-r', label='Infectious')
pl.legend(loc=0)
pl.title('Prediction of Simple nCOV-19 SIR model')
pl.xlabel('Time(day)')
pl.ylabel('individuals')
pl.show()
Input the accumulated number of tests: 9772 Input the accumulated number of positive results: 31 Input the accumulated number of releases: 12
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import os
for dirname, _, filenames in os.walk(r'C:\Users\Jaewoong\Desktop\AIFFEL\hackathon'):
for filename in filenames:
print(os.path.join(dirname, filename))
# Any results you write to the current directory are saved as output.
path = r'C:\\Users\\Jaewoong\\Desktop\\AIFFEL\\hackathon\\'
case = p_info = pd.read_csv(path+'Case.csv')
p_info = pd.read_csv(path+'PatientInfo.csv')
#p_route = pd.read_csv(path+'PatientRoute.csv')
################### Time ###################
time = pd.read_csv(path+'Time.csv')
t_age = pd.read_csv(path+'TimeAge.csv')
t_gender = pd.read_csv(path+'TimeGender.csv')
t_provin = pd.read_csv(path+'TimeProvince.csv')
region = pd.read_csv(path+'Region.csv')
weather = pd.read_csv(path+'Weather.csv')
search = pd.read_csv(path+'SearchTrend.csv')
floating = pd.read_csv(path+'SeoulFloating.csv')
policy = pd.read_csv(path+'Policy.csv')
C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\Case.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\PatientInfo.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\Policy.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\Region.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\SearchTrend.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\SeoulFloating.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\Time.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\TimeAge.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\TimeGender.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\TimeProvince.csv C:\Users\Jaewoong\Desktop\AIFFEL\hackathon\Weather.csv
import plotly.express as px
# df = px.data.iris()
fig = px.scatter(t_provin, x="date", y="confirmed", color="province", hover_data=['released'])
fig.show()
fig2 = px.scatter_3d(t_provin,
x='date',
y='confirmed',
z='released',
color='province',
opacity=0.7)
fig2.show()
weather['date_int'] = weather['date'].agg(lambda x: int(''.join(x.split('-'))))
prev_weather_idx = weather[weather['date_int'] < 20200120].index
weather_s20200120 = weather.drop(prev_weather_idx)
weather_s20200120 = weather_s20200120.reset_index(drop=True)
fig3 = px.scatter_3d(weather_s20200120,
x='date',
y='avg_temp',
z='avg_relative_humidity',
color='province',
opacity=0.7,
size_max=20)
fig3.update_traces(marker={"opacity": 0.7, "size":2})
fig3.show()
fig4 = px.scatter_matrix(weather_s20200120,
dimensions=["avg_temp", "most_wind_direction", "avg_relative_humidity", "precipitation"],
color='province')
fig4.update_traces(diagonal_visible=False)
fig4.update_traces(marker={"opacity": 0.7, "size":5})
fig4.update_layout(autosize=False, width=1000, height=800)
fig4.show()
t_provin['date_int'] = t_provin['date'].agg(lambda x: int(''.join(x.split('-'))))
filtered_t_provin_idx = t_provin[t_provin['date_int'] > weather_s20200120.date_int.max()].index
t_provin_e20200629 = t_provin.drop(filtered_t_provin_idx)
t_provin_e20200629 = t_provin_e20200629.reset_index(drop=True)
t_provin_weather = pd.merge(t_provin_e20200629, weather_s20200120, on=['date', 'province', 'date_int'], how='left').fillna(0)
# for i in t_provin_weather.province.unique():
# pd_provin = t_provin_weather[t_provin_weather['province'] == i]
# fig5 = px.scatter_matrix(pd_provin,
# dimensions=["confirmed", "released", "avg_temp", "most_wind_direction", "avg_relative_humidity"],
# color='province', title=i)
# fig5.update_traces(diagonal_visible=False)
# fig5.update_traces(marker={"opacity": 0.7, "size":5})
# fig5.update_layout(autosize=False, width=1000, height=800)
# # fig5.write_html(f'{i} scatter graph')
# fig5.show()
i = 'Seoul'
pd_provin = t_provin_weather[t_provin_weather['province'] == i]
fig5 = px.scatter_matrix(pd_provin,
dimensions=["confirmed", "released", "avg_temp", "most_wind_direction", "avg_relative_humidity"],
color='province', title=i)
fig5.update_traces(diagonal_visible=False)
fig5.update_traces(marker={"opacity": 0.7, "size":5})
fig5.update_layout(autosize=False, width=1000, height=800)
# fig5.write_html(f'{i} scatter graph')
fig5.show()